<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Member extends Model
{
    //指定表名
    protected $table = 'member'; //指定表名，默认是模型名的复数 members
    const SEX_UN = 0;
    const SEX_BOY = 1;
    const SEX_GIRL = 2;
//指定主键
    protected $primaryKey = 'member_id'; //指定主键，默认id

//是否开启时间戳
    public $timestamps = true;
    const CREATED_AT = null;
    const UPDATED_AT = null;

//设置时间戳格式为Unix
    protected $dateFormat = 'U';

//过滤字段，只有包含的字段才能被更新
    protected $fillable = ['name','sex','phone','pwd','address','email','is_delete'];

//隐藏字段
    protected $hidden = ['pwd'];

    /**
     * 避免转换时间戳为时间字符串
     * @return int|string
     */
    public function getDateFormat(){
        return time();
    }


    /**
     * select的时候避免转换时间为Carbon
     * @param mixed $value
     * @return \Illuminate\Support\Carbon|mixed
     */
    protected function asDateTime($value)
    {
        return $value;
    }

    public function sex($ind = null){
        $arr = [
            self::SEX_UN => '未知',
            self::SEX_BOY => '男',
            self::SEX_GIRL => '女',
        ];
        if ($ind !== null) {
            return array_key_exists($ind, $arr) ? $arr[$ind] : $arr[self::SEX_UN];
        }
        return $arr;
    }
}
